package dao

import "blog_server/internal/model/entity"

func (d Dao) GetAllCategory() ([]entity.Category, error) {
	var category entity.Category
	return category.Get(d.engine)
}

func (d Dao) GetCategoryNameByID(id uint) (string, error) {
	class := entity.Category{
		ID: id,
	}
	return class.GetCategoryNameByID(d.engine)
}

func (d Dao) CreateCategory(category *entity.Category) error {
	return category.Create(d.engine)
}

func (d Dao) GetCategoriesByPagination(offset, pageSize int) ([]entity.Category, error) {
	category := entity.Category{}
	return category.GetByPagination(d.engine, offset, pageSize)
}

func (d Dao) CountCategories() (int, error) {
	category := entity.Category{}
	return category.Count(d.engine)
}

func (d Dao) UpdateCategory(category entity.Category) error {
	return category.Update(d.engine)
}

func (d Dao) DeleteCategory(category entity.Category) error {
	return category.Delete(d.engine)
}

func (d Dao) GetCategoriesBySearchText(text string) ([]entity.Category, error) {
	c := entity.Category{}
	return c.GetBySearchText(d.engine, text)
}
